<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>


<script>
    let arr1 = [
        {totlehour:"50", state:1,project:"a"},
        {totlehour:"40",state:2,project:"a"},
        {totlehour:"30",state: 3,project:"a"},
        {totlehour:"20",state: 1,project:"b"},
        {totlehour:"20",state: 1,project:"c"}

    ]
    let arr2 = [
        {
            totlehour1:'',
            totlehour2:'',
            totlehour3:''
        }
    ]

    const groupBy = (list, fn) => {
         const groups = [];
         list.forEach(function (o) {
             const group = JSON.stringify(fn(o));
             groups[group] = groups[group] || [];
             groups[group].push(o);
         });
         return groups;
     }

     let groupData = groupBy(arr1, (link) => {
         return link.project
     })
     console.log(groupData)
    for(var i in groupData){
        console.log(i);
    }
</script>
</body>
</html>